#!perl
package DataMgr;
use strict;
use warnings;
use DBI ();

my $dbh;
my $instance;
my $config;
my @status = ['initialize', 'running', 'complete', 'fail'];
sub getInstance {
	return $instance if $instance;
	my ($class) = @_;
	$dbh = DBI->connect("DBI:mysql:database=metadata;host=localhost", "root", "txwllb", {'RaiseError' => 1});
	my $site = 'mtime';
	require "Configs\\$site.pm";
	$config = eval "\$Configs::${site}::config";
	my $self = {
		
	};
	$instance = bless $self, $class;
	return $instance;
}

sub getTasks {
	my ($self, $totalWantTo) = @_;
	my @queen;
	my $sth = $dbh->prepare("select * from task order by pri desc limit ?", undef, $totalWantTo);
	$sth->execute();
	while (my $ref = $sth->fetchrow_hashref()) {
		push @queen, '
	}
	$sth->finish();
	return \@queen;
}

sub setStatus {
	my ($self, $queen) = @_;
	for (@{$queen}) {
		my @task = split /\|/, $_;
		#print "task:$_  ", $task[0], "\n";
		if ($task[1] eq 'status:complete') {
			$completeTaskQueen{$task[0]} = 1	
		} else {
			push @taskQueen, $_;	
		}
	}
}

sub setNewTasks {
	my ($self, $queen) = @_;
	for (@{$queen}) {
		unshift @taskQueen, $_ . '|status:init' unless $completeTaskQueen{$_};	
	}
}

sub setResults {
	my ($self, $queen) = @_;
}
1;
